package cn.cutie.clot.gateway.plugin;

import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * @Description:
 * @Author: Cutie
 * @CreateDate: 2024/6/5 00:41
 * @Version: 0.0.1
 */
public abstract class AbstractGatewayPlugin implements GatewayPlugin{
    @Override
    public void start() {

    }

    @Override
    public void stop() {

    }

    @Override
    public Mono<Void> handle(ServerWebExchange exchange, GatewayPluginChain chain) {
        boolean supported = support(exchange);
        System.out.println("===>>> plugin[" + this.getName() + "], support=" + supported);
//        return supported ? doHandle(exchange) : Mono.empty();
        return supported ? doHandle(exchange, chain) : chain.handle(exchange);
    }

    @Override
    public boolean support(ServerWebExchange exchange) {
        return doSupport(exchange);
    }

    public abstract Mono<Void> doHandle(ServerWebExchange exchange, GatewayPluginChain chain);
    public abstract boolean doSupport(ServerWebExchange exchange);
}
